<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="../../style/css/back/style.css"  rel="stylesheet" type="text/css">
    <script src="../../style/js/jquery-1.8.3.js"></script>
    <script type="text/javascript">
          $(function (){
                //页面打开后,自动向servlet发送请求
              $.get("../../admin/admins",function (res){
                 if(res.code==202){
                     window.parent.location.replace("../login.html");
                 }else if(res.code==500){
                     alert("服务器忙,请稍后再试!");
                 }else{
                   var str="";

                    for(i=0;i<res.data.length;i++){
                        var imgsrc =  "http://127.0.0.1:8080/userImg/"+res.data[i].account+"/"+res.data[i].newFileName;
                        str += "<tr align='center'>";
                        str+="<td>"+(i+1)+"</td>";
                        str+="<td>"+res.data[i].account+"</td>";

                        str+="<td>"+res.data[i].sex+"</td>";
                        str+="<td><img src='"+imgsrc+"' width='30' height='30'/></td>";
                        str+="<td>";
                        for (j=0;j<res.data[i].roleList.length;j++){
                               str+=res.data[i].roleList[j].name+",";
                        }
                        str+="</td>";
                        str+="<td><a href='javaScript:void(0)' onclick='toupdate("+res.data[i].id+")' class='tablelink'>修改</a> " +
                            "     <a href='javaScript:void(0)' onclick='del("+res.data[i].id+")' class='tablelink'>删除</a></td>";
                        str+="</tr>";
                    }
                   $("#tableId").append(str);
                 }
              },"json");
          })

          function toupdate(id){
              location.assign("update.html?id="+id);
          }
    </script>
</head>
<body>
<div class="rightinfo">
    <!-- 顶部按钮 -->
    <div class="tools">
        <ul class="toolbar">
                <a href="add.html">
                    <li class="click">
                        <span><img src="../../style/img/back/t01.png" /></span>
                        添加
                    </li>
                </a>
        </ul>
    </div>
    <!--数据列表 -->
    <table class="tablelist" id="tableId">
       <tr>
           <th>序号</th>
           <th>账号</th>

           <th>性别</th>
           <th>头像</th>
           <th>角色</th>
           <th>操作</th>
       </tr>
    </table>
</div>
</body>
</html>